<template>
  <div class="system-role-container layout-padding">

    <div class="system-role-padding layout-padding-auto layout-padding-view">
      <div class="system-user-search mb15">
        <el-input size="default" v-model="state.keyword" placeholder="请输入关键字" style="max-width: 180px" clearable> </el-input>
        <el-button size="default" type="primary" class="ml10" @click="getTableData()">
          <el-icon> <ele-Search /> </el-icon>
          查  询
        </el-button>
      </div>

      <el-table :data="state.tableData.data" ref="multipleTable" v-loading="state.tableData.loading" stripe style="width: 100%">
<!--        <el-table-column type="selection" width="50" />-->
        <el-table-column type="index" label="序号" width="60" />
          <el-table-column prop="code" label="日志代码" show-overflow-tooltip width="245"></el-table-column>
          <el-table-column prop="ip" label="操作IP" show-overflow-tooltip width="130"></el-table-column>
          <el-table-column prop="operator" label="操作人" show-overflow-tooltip width="120"></el-table-column>
        <el-table-column prop="result" label="状态" show-overflow-tooltip width="100">
          <template #default="scope">
            <el-tag type="success" v-if="scope.row.result==1">成功</el-tag>
            <el-tag type="info" v-else>失败</el-tag>
          </template>
        </el-table-column>
          <el-table-column prop="createDate" label="创建日期" show-overflow-tooltip width="180"></el-table-column>
          <el-table-column prop="spentTime" label="耗时(ms)" show-overflow-tooltip width="100"></el-table-column>
        <el-table-column prop="param" label="标识ID" show-overflow-tooltip width="140"></el-table-column>
        <el-table-column prop="remark" label="备注" show-overflow-tooltip></el-table-column>

      </el-table>
      <el-pagination
          @size-change="(val: number)=>{state.tableData.param.pageSize = val; getTableData();}"
          @current-change="(val: number) => {state.tableData.param.pageNum = val;getTableData();}"
          class="mt15"
          :pager-count="5"
          :page-sizes="[10, 20, 30]"
          v-model:current-page="state.tableData.param.pageNum"
          background
          v-model:page-size="state.tableData.param.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="state.tableData.total"
      >
      </el-pagination>
    </div>

  </div>
</template>

<script setup lang="ts" name="systemDic">
import {reactive, onMounted, ref} from 'vue';
import {ElMessageBox} from 'element-plus';
import { api } from '/@/api/system/admin_log_api.ts';

// 定义变量内容
const multipleTable = ref();
interface RowData {
    id?: string;
    operateType?: number;
   
   code?: string;
   
   param?: string;
   
   result?: number;
   
   remark?: string;
   
   ip?: string;
   
   operator?: string;
   
   spentTime?: number;
 
}
// 数据绑定
const state = reactive({
  tableData: {
    data: [],
    total: 0,
    loading: false,
    param: {
      pageNum: 1,
      pageSize: 10,
    },
  },
  keyword: '',
  ruleForm: <RowData>({}),
  dialog: {
    isShowDialog: false,
    type: '',
    title: '',
    submitTxt: '',
  },
});

//-------------------------------------------------------------------
//-------------------------------------------------------------------
// 查询表格数据
const getTableData = () => {
  state.tableData.loading = true;
  const param = {
    keyword: state.keyword,
    pageNum: state.tableData.param.pageNum,
    pageSize: state.tableData.param.pageSize
  }
  api().list(param).then(res=>{
    state.tableData.data = res.data.list;
    state.tableData.total = res.data.total;
  })
  .catch(err => {ElMessageBox.alert(err, '操作异常', {confirmButtonText: '确定'});})
  .finally(() => {state.tableData.loading = false;})
};

//-------------------------------------------------------------------
// 页面加载时
onMounted(() => {
  getTableData();
});

</script>


